<template>
  <card ref="Card">
    <div slot="header">
      <span>帮助中心列表</span>
      <el-button class="float-right" type="primary" @click="add">新增</el-button>
    </div>
    <el-table :data="formData">
      <el-table-column prop="content" label="电话"/>
      <el-table-column prop="createTime" label="创建时间" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime | formatDateTime}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" width="150">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" @click.stop="edit(scope.row)"></el-button>
          <delete-button
              :ref="scope.row.id"
              :id="scope.row.id"
              @start="deletePhone"/>
        </template>
      </el-table-column>
    </el-table>
    <add ref="Add" @update="getPhone"></add>
    <edit ref="Edit" @update="getPhone"></edit>
  </card>
</template>

<script>
  import {listHelpApi, delHelpApi} from '@/api/website/help';
  import {objectEvaluate} from "@/utils/common";
  import Add from './add';
  import Edit from './edit';

  export default {
    name: 'Help',
    components: {Edit, Add},
    data() {
      return {
        formData: []
      }
    },
    mounted() {
      this.getPhone();
    },
    methods: {
      getPhone() {
        this.$refs.Card.start();
        listHelpApi().then(result => {
          this.$refs.Card.stop();
          this.formData = result.resultParam.helpList;
        })
      },
      add() {
        this.$refs.Add.visible = true
      },
      edit(obj) {
        let _this = this.$refs.Edit;
        objectEvaluate(_this.form, obj);
        _this.visible = true
      },
      deletePhone(id) {
        delHelpApi({id: id})
          .then(() => {
            this.getPhone();
            this.$refs[id].close()
          })
          .catch(() => {
            this.$refs[id].stop();
          })
      }
    }
  }
</script>
